#include "stdafx.h"
#include <osg/AutoTransform>
#include <osgText/Text>
using namespace osgText;
Node* createAutoTransformNode(Vec3& pos,float size,string& label,
							  AutoTransform::AutoRotateMode autoMode,
							  Text::AxisAlignment axisAlign)
{
	Geode* txtNode=new Geode();
	string font("fonts/cour.ttf");
	Text* txtObj=new Text();
	txtNode->addDrawable (txtObj);

	txtObj->setFont(font);
	txtObj->setFontResolution(128.0f,128.0f);
	txtObj->setCharacterSize(size);
	txtObj->setAlignment(Text::CENTER_CENTER);
	txtObj->setAxisAlignment(axisAlign);
	txtObj->setText(label);

	StateSet* states=txtNode->getOrCreateStateSet();
	states->setMode(GL_LIGHTING,StateAttribute::OFF);

	AutoTransform* at=new AutoTransform();
	at->setAutoRotateMode(autoMode);
	at->setAutoScaleToScreen(false);
	at->setMinimumScale(0.0f);
	at->setMaximumScale(5.0f);
	at->setPosition(pos);
	at->addChild(txtNode);
    return at;	
}
int UCAutoTransform()
{
	string text("hello");
	Group* root=new Group();
	Vec3 pos(0.0f,0.0f,0.0f);
	Node* fstNode=createAutoTransformNode(pos,60.0f,text,
		AutoTransform::AutoRotateMode::NO_ROTATION,Text::XY_PLANE);

	Node* secNode=createAutoTransformNode(pos,60.f,text,
		AutoTransform::AutoRotateMode::ROTATE_TO_CAMERA,Text::YZ_PLANE);

	Node* trdNode=createAutoTransformNode(pos,60.0f,text,
		AutoTransform::AutoRotateMode::ROTATE_TO_SCREEN,Text::XY_PLANE);

	root->addChild(fstNode);
	root->addChild(secNode);
	root->addChild(trdNode);

	Viewer* runer=new Viewer();
	runer->setSceneData(root);
	runer->realize();
	runer->run();
	return 0;
}